<?php
    require_once('../code/global.php');
    require_once('/code/Admin.php');
    require_once('/code/Category.php');
    require_once('/code/Product.php');
    $admin=new Admin();
    $admin->loginCheck(1);
    $category=new Category();
    if(isset($_GET['cid'])) $cid=intval($_GET['cid']);
    else $cid=$category->getFirstCategoryId();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Xiaosha Sculpture 后台管理系统</title>
        <link rel="stylesheet" href="/styles/admin.css" type="text/css" media="all">
        <script type="text/javascript" src="/script/jquery-1.6.1.min.js"></script>
        <script type="text/javascript" src="/script/script.js"></script>
        <script type="text/javascript">
            window.parent.scroll(0,0);
        </script>
    </head>
    <body>
        <?php
            if(isset($_GET['msg'])) echo '<div class="msgBox">'.$_GET['msg'].'</div>';
            else echo '<div class="msgBox">作品管理</div>';
                
        ?>
        <table border="0" cellspacing="0" cellpadding="0" class="detailTable">
        <form name="addItem" action="exec.php" method="post" enctype="multipart/form-data">
            <input type="hidden" name="action" value="addItem"><input type="hidden" name="max_file_size" value="10000000">
            <tr class="header"><td class="thumbTd">分类
                <select name="category_id" onchange="location.href='items.php?cid='+this.options[this.selectedIndex].value">
                    <?php
                        $category=new Category();
                        $c=$category->getCategories(0);
                        $c_count=count($c);
                        $i=0;
                        while($i<$c_count){
                            echo '<option value="'.$c[$i]['category_id'].'"'.($c[$i]['category_id']==$cid?' selected':'').'>'.$c[$i]['name'].'</option>';
                            ++$i;
                        }
                    ?>
                </select>
            </td><td colspan="2" class="uploadTd"><input type="file" name="imgFile"><input class="btnLnk" type="submit" id="btnUpload" value="Add New Piece" onclick="wait()"></td></tr>
        </form>
        <?php
            $product=new Product();
            $p=$product->getProductsByCategory($cid,0);
            $p_count=count($p);
            $i=0;
            if($p_count==0) echo '<tr><td colspan="3" class="align-center">此分类下还没有作品</td></tr>';
            while($i<$p_count){
                $title='';
                $pid=$p[$i]['product_id'];
                echo '<tr><td class="thumbTd"><img src="'.$p[$i]['thumb_url'].'" alt="'.($i+1).'"/></td><td class="infoTd">';
        ?>
        <table border="0" cellspacing="0" cellpadding="0" class="photoInfoTable">
        <tr><td colspan="2"><div><span class="title">Subject: </span><?php echo $p[$i]['subject'];?></div></td></tr>
        <tr><td colspan="2"><div><span class="title">Artist: </span><?php echo $p[$i]['name'];?></div></td></tr>
        <tr><td><div><span class="title">Date: </span><?php echo $p[$i]['date'];?></div></td><td><div><span class="title">Code: </span><?php echo $p[$i]['code'];?></div></td></tr>
        <tr><td colspan="2"><div><span class="title">Location: </span><?php echo $p[$i]['location'];?></div></td></tr>
        <tr><td colspan="2"><div><span class="title">Material: </span><?php echo $p[$i]['material'];?></div></td></tr>
        <tr><td colspan="2"><div><span class="title">Size: </span><?php echo $p[$i]['size'];?></div></td></tr>
        <tr></tr>
        <tr class="bottomTr"><td><div><span class="title">Price: </span><?php echo $p[$i]['price'];?>￡</div></td><td><div><span class="title">Sold</span><input type="checkbox"  disabled<?php echo $p[$i]['is_sold']==1?' checked':'';?>> <span class="title">Active</span><input type="checkbox"  disabled<?php echo $p[$i]['is_active']==1?' checked':'';?>></div></td></tr>
        </table>
        <?php
                echo '</td><td class="align-center"><input class="btnLnk" type="button" value="Edit" onclick="location.href=\'editItem.php?pid='.$pid.'&cid='.$cid.'\'"><br /><br /><form name="deleteItem'.$pid.'" action="exec.php" method="post"><input type="hidden" name="action" value="deleteItem"><input type="hidden" name="product_id" value="'.$pid.'"><input type="hidden" name="category_id" value="'.$cid.'"><input class="btnLnk btnDel" type="submit" value="Delete"></form></td></tr>';
                ++$i;
            }
        ?>
    </table>
    </body>
</html>